#include "miss.h"
#define image_width 40
#define image_height 40

extern Preferences preferences;
String my_miss_count;
String couple_miss_count;

void drawRoundedRectangleWithImage(int x, int y, int w, int h, int r, uint16_t rectColor, uint16_t bgColor, const uint16_t* image) {
    // 画长方形主体
    tft.fillRect(x + r, y, w - 2 * r, h+1, rectColor);

    // 画右侧的半圆
    tft.fillCircle(x + w - r, y + h / 2, r, rectColor);

    // 为左侧圆形区域创建裁剪区域
    tft.startWrite();
    tft.setAddrWindow(x, y, 2*r, h);
    
    // 绘制圆形图像
    for (int j = -r; j < r; j++) {
        for (int i = -r; i < r; i++) {
            if (i*i + j*j <= r*r) {
                // 在圆内，绘制图像
                int imageX = (i + r) * image_width / (2*r);
                int imageY = (j + r) * image_height / (2*r);
                uint16_t pixel = image[imageY * image_width + imageX];
                tft.pushColor(pixel);
            } else {
                // 在圆外，根据位置填充不同颜色
                if (i < -r/2+6) {
                    // 圆心左侧用背景色填充
                    tft.pushColor(bgColor);
                } else {
                    // 圆心右侧用矩形色填充
                    tft.pushColor(rectColor);
                }
            }
        }
    }

    tft.endWrite();
}

String word1;

void show_miss_page(String word, uint16_t word_color)
{


    word1 = word;
    TFT_eSprite miu = TFT_eSprite(&tft);
    uint16_t pinkColor = tft.color565(255, 174, 201);
    uint16_t zongseColor = tft.color565(128, 64, 64);
    //显示想你图片
    
    miu.setColorDepth(16);
    if (word != "")
    {
            if (word.length() > 30) {
        miu.loadFont(KT20);
    } else {
        miu.loadFont(KT24);
    }
        miu.createSprite(240, 30);
        miu.fillSprite(Mint_Green);
        miu.setTextWrap(false);
        miu.setTextDatum(CC_DATUM);
        miu.setTextColor(Light_Apricot);
        miu.drawString(word, 120, 15);
        if (word == "已发送：我想你！"||word == "收到：宝贝，我想你辣！")
        miu.pushSprite(0, 80);
        else
        miu.pushSprite(0, 130);
        miu.deleteSprite();
        miu.unloadFont();
if (word == "已发送：我想你！"){ 
        drawRoundedRectangleWithImage(10, 140, 220, 40, 20, Sky_Blue,Mint_Green, MY_profilphoto);
        drawRoundedRectangleWithImage(10, 190, 220, 40, 20, LightBe_ige,Mint_Green,COUPLE_profilphoto);
     //第一个矩形框"我已经想宝宝"
       miu.loadFont(KT20);
       miu.createSprite(120, 30);
       miu.fillSprite(Sky_Blue);
       miu.setTextWrap(false);
       miu.setTextDatum(CC_DATUM);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("我已经想宝宝",60, 15);
       miu.pushSprite(50, 145);
       miu.deleteSprite();

// 第二个矩形框中"宝宝已经想我"
       miu.createSprite(120, 30);
       miu.fillSprite(LightBe_ige);
       miu.setTextWrap(false);
       miu.setTextDatum(CC_DATUM);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("宝宝已经想我", 60, 15);
       miu.pushSprite(50, 195);
       miu.deleteSprite(); 
//两个矩形框中”数字“
       miu.createSprite(55, 22);
       miu.fillSprite(Sky_Blue);
       miu.setTextColor(tft.color565(23,129,181));
       miu.drawString(my_miss_count,17, 15);
       miu.pushSprite(170,145);
       miu.deleteSprite(); 
       miu.createSprite(55, 22);
       miu.fillSprite(LightBe_ige);
       miu.setTextColor(tft.color565(210,53,125));
       miu.drawString(couple_miss_count,17, 15);
       miu.pushSprite(170,195);
       miu.deleteSprite(); 
       //第一个矩形框中"次"
       miu.createSprite(20, 20);
       miu.fillSprite(Sky_Blue);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("次",10, 10);
       miu.pushSprite(205, 150);
       miu.deleteSprite(); 
// 第二个矩形框中"次"
       miu.createSprite(20, 20);
       miu.fillSprite(LightBe_ige);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("次",10, 10);
       miu.pushSprite(205, 200);
       miu.deleteSprite(); 
       miu.unloadFont();
}
else  if (word == "收到：宝贝，我想你辣！"){
       drawRoundedRectangleWithImage(10, 140, 220, 40, 20, Sky_Blue,Mint_Green, MY_profilphoto);
        drawRoundedRectangleWithImage(10, 190, 220, 40, 20, LightBe_ige,Mint_Green,COUPLE_profilphoto);
     //第一个矩形框"我已经想宝宝"
       miu.loadFont(KT20);
       miu.createSprite(120, 30);
       miu.fillSprite(Sky_Blue);
       miu.setTextWrap(false);
       miu.setTextDatum(CC_DATUM);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("我已经想宝宝",60, 15);
       miu.pushSprite(50, 145);
       miu.deleteSprite();

// 第二个矩形框中"宝宝已经想我"
       miu.createSprite(120, 30);
       miu.fillSprite(LightBe_ige);
       miu.setTextWrap(false);
       miu.setTextDatum(CC_DATUM);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("宝宝已经想我", 60, 15);
       miu.pushSprite(50, 195);
       miu.deleteSprite(); 
//两个矩形框中”数字“
       miu.createSprite(55, 22);
       miu.fillSprite(Sky_Blue);
       miu.setTextColor(tft.color565(23,129,181));
       miu.drawString(my_miss_count,17, 15);
       miu.pushSprite(170,145);
       miu.deleteSprite(); 
       miu.createSprite(55, 22);
       miu.fillSprite(LightBe_ige);
       miu.setTextColor(tft.color565(210,53,125));
       miu.drawString(couple_miss_count,17, 15);
       miu.pushSprite(170,195);
       miu.deleteSprite(); 
       //第一个矩形框中"次"
       miu.createSprite(20, 20);
       miu.fillSprite(Sky_Blue);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("次",10, 10);
       miu.pushSprite(205, 150);
       miu.deleteSprite(); 
// 第二个矩形框中"次"
       miu.createSprite(20, 20);
       miu.fillSprite(LightBe_ige);
       miu.setTextColor(TFT_BLACK);
       miu.drawString("次",10, 10);
       miu.pushSprite(205, 200);
       miu.deleteSprite(); 
       miu.unloadFont();

}else{
    TJpgDec.drawJpg(70, 10, misu_img, sizeof(misu_img));
   if (word == "宝贝,快来连麦"){
    miu.loadFont(KT20);
    miu.createSprite(50, 20);
    miu.fillSprite(0xb75c);
    miu.setTextWrap(false);
    miu.setTextDatum(CC_DATUM);
    miu.setTextColor(zongseColor);
    miu.drawString("拒绝", 20, 10);
    miu.pushSprite(0, 220);
    miu.createSprite(40, 20);
    miu.fillSprite(0xb75c);
    miu.setTextWrap(false);
    miu.setTextDatum(CC_DATUM);
    miu.setTextColor(zongseColor);
    miu.drawString("接受", 20, 10);
    miu.pushSprite(200, 220);
    miu.deleteSprite();
    miu.setColorDepth(16);
    miu.unloadFont();
    miu.loadFont(KT24);
    miu.createSprite(240, 20);
    miu.fillSprite(Mint_Green);
    miu.setTextWrap(false);
    miu.setTextDatum(CC_DATUM);
    miu.setTextColor(zongseColor);
    miu.drawString("（单击按钮选择!）", 120, 11);
    //miu.drawString("接受！", 200, 13);
    }
    else
    {
    miu.setColorDepth(16);
    miu.loadFont(KT24);
    miu.createSprite(240, 20);
    miu.fillSprite(Mint_Green);
    miu.setTextWrap(false);
    miu.setTextDatum(CC_DATUM);
    miu.setTextColor(zongseColor);
    miu.drawString("（单击按钮退出!）", 120, 11);
    }
    miu.pushSprite(0, 180);
    miu.deleteSprite();
    miu.unloadFont();
  }


}

}


